<?php

class Ms_Form_Forum extends Zend_Form
{

    public function init()
    {
        $this->setMethod('post');
        // 主题标题
        $subject = $this->createElement('text', 'subject');
        $subject->setLabel('标题：');
        $subject->setRequired(TRUE);
        $subject->addValidator('stringLength', false, array(5, 50));
        $subject->addErrorMessage('标题应有5-50个汉字。');
        $this->addElement($subject);
        
        // 主题内容
        $post = $this->createElement('textarea', 'post');
        $post->setLabel('内容：');
        $post->setRequired(TRUE); 
        $this->addElement($post);
        
        // 回复
        $comment = $this->createElement('textarea', 'comment');
        $comment->setLabel('回复：');
        $comment->setRequired(TRUE);
        $this->addElement($comment);
        
        // 提交按钮
        $submit = $this->createElement('submit', '提交');
        $this->addElement($submit);
        
        /**
         +----------------------------------------------------------
         * 覆写装饰器
         +----------------------------------------------------------
        */
        
        $this->setElementDecorators(array(
                'ViewHelper',
                'Errors',
                array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')),
                array('Label', array('tag' => 'td')),
                array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')),
           ));
           
           $submit->setDecorators(array(
                array(
                'decorator' => 'ViewHelper',
                'options' => array('helper' => 'formSubmit')),
                array(
                'decorator' => array('td' => 'HtmlTag'),
                'options' => array('tag' => 'td', 'colspan' => 2)),
                array(
                'decorator' => array('tr' => 'HtmlTag'),
                'options' => array('tag' => 'tr')),
        ));
           
           $this->addDecorator('FormElements')
           ->addDecorator('HtmlTag', array('tag' => 'table'))
           ->addDecorator('Form');
    }

}

